package category.web.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import seed.service.SeedService;

import category.service.CategoryService;
import cn.itcast.servlet.BaseServlet;

public class CategoryServlet extends BaseServlet {
          CategoryService categoryService = new  CategoryService();
          
          SeedService seedService = new SeedService ();
          
          public String findAll(HttpServletRequest request, HttpServletResponse response)
      			throws ServletException, IOException {
        	request.setAttribute("categoryList", categoryService.findAll());
      		String cid = request.getParameter("cid");
      		String pc = request.getParameter("pc") == null ? "1":request.getParameter("pc");
      		
      		if(cid != null)
      		{
      			request.setAttribute("pb", seedService.findByCategory(cid,Integer.parseInt(pc),4));
      		}
      		else
      		{
      			request.setAttribute("seedList",null);
      		}
      		request.setAttribute("cid",cid);
      		return "f:/category2.jsp";
      	}
}
